

package com.zdkj.subway.rca.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.constant.SecurityConstants;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.service.PigxUser;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.common.security.util.SecurityUtils;
import com.zdkj.subway.rca.dto.SwCkClearSystemCompareExcelExportDTO;
import com.zdkj.subway.rca.dto.SwCkClearSystemCompareNoticeConfirmDTO;
import com.zdkj.subway.rca.entity.SwCkClearSystemCompare;
import com.zdkj.subway.rca.entity.SwMessage;
import com.zdkj.subway.rca.feign.SubwaySupportService;
import com.zdkj.subway.rca.service.SwCkClearSystemCompareService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


/**
 * 系统清分数据对比,废弃不用了
 *
 * @author cooze
 * @date 2020-10-31 21:40:25
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swckclearsystemcompare")
@Api(value = "swckclearsystemcompare", tags = "清分及划账-系统清分数据对比(废弃)")
public class SwCkClearSystemCompareController {

    private final SwCkClearSystemCompareService swCkClearSystemCompareService;

    /**
     * 分页查询 (功能废弃了)
     *
     * @param page 分页对象
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询", hidden = true)
    @GetMapping("/page")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "lineCode", value = "线路编码", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "startDate", value = "开始日期：yyyy-MM-dd", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "endDate", value = "结束日期：yyyy-MM-dd", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "confirmStatus", value = "确认状态：0未确认、1已确认", dataTypeClass = String.class),
                    @ApiImplicitParam(name = "noticeStatus", value = "通知状态 1：已通知、0：未通知", dataTypeClass = String.class)
            }
    )
    public R getSwCkClearSystemComparePage(Page page, String lineCode,
                                           String startDate,
                                           String endDate,
                                           String confirmStatus,
                                           String noticeStatus) {
        SwCkClearSystemCompare swCkClearSystemCompare = new SwCkClearSystemCompare();
        if (StringUtils.isNotEmpty(lineCode)) {
            swCkClearSystemCompare.setLineCode(lineCode);
        }
        if (StringUtils.isNotEmpty(confirmStatus)) {
            swCkClearSystemCompare.setConfirmStatus(confirmStatus);
        }
        if (StringUtils.isNotEmpty(noticeStatus)) {
            swCkClearSystemCompare.setNoticeStatus(noticeStatus);
        }
        boolean isDateCondition = StringUtils.isNotEmpty(startDate) && StringUtils.isNotEmpty(endDate);
        return R.ok(swCkClearSystemCompareService.page(page, Wrappers.query(swCkClearSystemCompare)
                .lambda().between(isDateCondition, SwCkClearSystemCompare::getTradeDate, startDate, endDate)));
    }

    /**
     * 差异分类(可能用不到，暂时设置hidden = true)
     *
     * @return R
     */
    @ApiOperation(value = "差异分类", notes = "差异分类", hidden = true)
    @GetMapping("/queryDiffType")
    public R queryDiffType() {
        return R.ok(swCkClearSystemCompareService.queryDiffType());
    }
    /**
     * 差异确认
     * @param dto
     * @return
     */
    @ApiOperation(value = "确认", notes = "确认", hidden = true)
    @PostMapping("/batchConfirm")
    @PreAuthorize("@pms.hasPermission('rca_swckclearsystemcompare_confirm')")
    public R batchConfirm(@RequestBody SwCkClearSystemCompareNoticeConfirmDTO dto) {
        swCkClearSystemCompareService.batchConfirm(dto);
        return R.ok();
    }
    /**
     * 发送通知
     * @param dto
     * @return
     */
    @ApiOperation(value = "通知", notes = "通知", hidden = true)
    @PostMapping("/batchNotice")
    @PreAuthorize("@pms.hasPermission('rca_swckclearsystemcompare_notice')")
    public R batchNotice(@RequestBody SwCkClearSystemCompareNoticeConfirmDTO dto) {
        PigxUser user = SecurityUtils.getUser();
        dto.setCreatorId(user.getId());
        dto.setCreatorName(user.getNikeName());
        dto.setDeptId(user.getDeptId());
        dto.setLineCode(user.getLineCode());
        swCkClearSystemCompareService.batchNotice(dto);
        return R.ok();
    }

    @ApiOperation(value = "导出", notes = "导出", hidden = true)
    @PostMapping("/excelExport")
    @PreAuthorize("@pms.hasPermission('rca_swckclearsystemcompare_excel_export')")
    public void excelExport(@RequestBody SwCkClearSystemCompareExcelExportDTO dto, HttpServletResponse response) {
        swCkClearSystemCompareService.excelExport(dto, response);
    }


    /**
     * 通过id查询系统清分数据对比
     *
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询", hidden = true)
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(swCkClearSystemCompareService.getById(id));
    }


}
